#-*- coding: utf-8 -*-

class Services():
    svclst = {}
    errors = []
    def __init__(self,comlist):
        tmpsvclst = []
        for n,o in comlist.items():
            if o.provides:
                for sv in o.provides:
                    if sv["name"] not in [x["name"] for x in tmpsvclst]:
                        tmpsvclst.append({"name":sv["name"],"component":o.name,"value":sv["value"]})
                    else:
                        for s in tmpsvclst:
                            if s["name"] == sv["name"]:
                                self.errors.append(s["component"] + " - " 
                                + s["name"] + " with " + o.name + " - " 
                                + sv["name"])
        for s in tmpsvclst:
            self.svclst[s["name"]] = s["value"]

    def get(self,name):
        if self.svclst.has_key(name):
            return self.svclst[name]
        else:
            return None

    def add(self,name,value):
        svclst[name] = value
